// import React, { useEffect, useState } from 'react'
import { Button, Checkbox, Form, Input } from 'antd';
import  store  from '../../store/index.js';
import { getuser } from '../../store/userSlice';
import { useSelector,useDispatch } from 'react-redux'

export default function Login() {
    const us = useSelector(state=>state.user.user)
    // const [us, setUs] = useState(store.getState().user.user)
    const dispatch = useDispatch()
    // useEffect(() => {
    //     //侦听变化
    //     store.subscribe(() => {
    //         let us = store.getState().user.user
    //         setUs(us)
    //     })
    // })

    return (
        <div>
            <h2>
                {us}
            </h2>
            <Button type='button' onClick={()=>{dispatch(getuser({user1:"123"}))}}>变更</Button>
            <Form name="basic"
                labelCol={{
                    span: 8,
                }}
                wrapperCol={{
                    span: 8,
                }}
                initialValues={{
                    remember: true,
                }}
                autoComplete="off">
                <Form.Item
                    label="账号"
                    name="username"
                    rules={[
                        {
                            required: true,
                            message: 'Please input your username!',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="密码"
                    name="password"
                    rules={[
                        {
                            required: true,
                            message: 'Please input your password!',
                        },
                    ]}
                >
                    <Input.Password />
                </Form.Item>
                <Form.Item
                    name="remember"
                    valuePropName="checked"
                    wrapperCol={{
                        offset: 8,
                        span: 16,
                    }}
                >
                    <Checkbox>记住密码</Checkbox>
                </Form.Item>
                <Form.Item
                    wrapperCol={{
                        offset: 10,
                        span: 4,
                    }}
                >
                    <Button type="primary" htmlType="submit">
                        登录
                    </Button>
                </Form.Item>
            </Form>
        </div>
    )
}
